import unittest
from dictionary import Dictionary
import dictionaryinfo


class DictionaryTest(unittest.TestCase):
    def setUp(self):
        Dictionary.invalidate()

    def tearDown(self):
        Dictionary.invalidate()

    def test_get_words(self):
        """Tests get_words in Dictionary

        """

        self.assertEqual(Dictionary.loaded_dictionary, None)
        some_dictionary = Dictionary.get_dict(None)
        self.assertEquals(some_dictionary, Dictionary.get_dict(None))
        self.assertEqual(some_dictionary, Dictionary.get_dict(None))
        self.assertEqual(Dictionary.loaded_dictionary, some_dictionary)
        Dictionary.invalidate()
        self.assertEqual(Dictionary.loaded_dictionary, None)
        some_dictionary = Dictionary.get_dict(None)
        self.assertTrue(Dictionary.loaded_dictionary is not None)
        Dictionary.make_json()

        count = 1868
        dicts = dictionaryinfo.DictionaryInfo.parse_dictionaries_metadata()

        list_of_words = some_dictionary.get_words(count, ['123', '456'])

        for word in list_of_words:
            self.assertTrue(type(word) == unicode)
        self.assertEqual(len(set(list_of_words)), len(list_of_words))
        self.assertTrue(
            set(list_of_words) <=
            set([word.text for word in some_dictionary.dictionary_words]))

if __name__ == "__main__":
    unittest.main()
